*
* Replication file for Experiment 1 analysis in:
*
* On the Merits of Separate Spaces: Why Institutions Isolate Cooperation and Division Tasks
* By Scott E. Bokemper and Gregory A. Huber
* Political Behavior
*
* This is a stata .do file  
* Version 1.0, May 24, 2023

* Note: This code uses this Stata version of the outreg package for table export
* net install sg97_4.pkg
which outreg
* Should return the following:
*! Write formatted regression output to a text file
*! version 4.10  30nov2011 by John Luke Gallup (jlgallup@pdx.edu)

capture log close
clear
set more off
log using Experiment1AnalysisLog.txt, text replace

use experiment1_analysisdataset.dta, replace

* First description, own (unimplemented) proposed split in Division Game
tab DG_Own_Proposal

* Second analysis, effect of either unfair division on policy adoption, ignoring everything else
recode T_DG_Partner_Given (20=0) (10=1) (0=1) (*=.), gen(t_eitherunfair)
label var t_eitherunfair "DG Outcome Unfair"
tab t_eitherunfair PG_proposal , row
regress PG_proposal t_eitherunfair
drop t_eitherunfair

* Setup regression analysis
gen T_DGGot0=T_DG_Partner_Given==0
label var T_DGGot0 "Division Game Got 0"
gen T_DGGot10=T_DG_Partner_Given==10
label var T_DGGot10 "Division Game Got 10"
gen T_PGNet10=T_policynetpayoff==10
label var T_PGNet10 "Policy Game Nets 10"
gen T_PGNet20=T_policynetpayoff==20
label var T_PGNet20 "Policy Game Nets 20"
gen T_SamePerson=T_partnertype==1
label var T_SamePerson "Partner is Same Person"
gen TX_Got0xSame=T_SamePerson*T_DGGot0
label var TX_Got0xSame "Division Game Got 0 x Same Person"
gen TX_Got10xSame=T_SamePerson*T_DGGot10
label var TX_Got10xSame "Division Game Got 10 x Same Person"

* Column 1 model
regress PG_proposal T_DGGot0 T_DGGot10, robust
lincom T_DGGot0-T_DGGot10
outreg, se squarebrack bdec(2) starlevels(10 5 1) nolegend starloc(1) varlabels sigsymbols(* ** ***) ctitles("","(1)") replace

* Column 2 model
regress PG_proposal T_DGGot0 T_DGGot10 T_PGNet10 T_PGNet20, robust
outreg, se squarebrack bdec(2) starlevels(10 5 1) nolegend starloc(1) varlabels sigsymbols(* ** ***) ctitles("","(2)") merge

* Column 3 model
regress PG_proposal T_DGGot0 T_DGGot10 T_PGNet10 T_PGNet20 T_SamePerson TX_Got0xSame TX_Got10xSame, robust
lincom T_DGGot0+TX_Got0xSame
lincom T_DGGot10 +TX_Got10xSame
lincom (T_DGGot0+TX_Got0xSame)-(T_DGGot10 +TX_Got10xSame)
outreg using Table3.rtf, se squarebrack bdec(2) starlevels(10 5 1) nolegend starloc(1) varlabels sigsymbols(* ** ***) ctitles("","(3)") merge replace

* Appendix Table A1, counts by treatment cells
bysort T_partnertype : tab T_DG_Partner_Given T_policynetpayoff

* Partitioning by whether policy is not 0 payoff, Appendix Table A2
regress PG_proposal T_DGGot0 T_DGGot10 T_SamePerson TX_Got0xSame TX_Got10xSame if T_policynetpayoff==0, robust
lincom T_DGGot0+TX_Got0xSame
outreg, se squarebrack bdec(2) starlevels(10 5 1) nolegend starloc(1) varlabels sigsymbols(* ** ***) ctitles("","Net Policy Payoff 0") replace

regress PG_proposal T_DGGot0 T_DGGot10 T_PGNet20 T_SamePerson TX_Got0xSame TX_Got10xSame if T_policynetpayoff!=0, robust
lincom T_DGGot0+TX_Got0xSame
outreg using AppendixTableA2.rtf, se squarebrack bdec(2) starlevels(10 5 1) nolegend starloc(1) varlabels sigsymbols(* ** ***) ctitles("","Net Policy Payoff 10 or 20") merge replace

* Partitioning by own DG proposal, Appendix Table, Appendix Table A3
regress PG_proposal T_DGGot0 T_DGGot10 T_PGNet10 T_PGNet20 T_SamePerson TX_Got0xSame TX_Got10xSame if DG_Own_Proposal==20, robust
lincom T_DGGot0+TX_Got0xSame
outreg, se squarebrack bdec(2) starlevels(10 5 1) nolegend starloc(1) varlabels sigsymbols(* ** ***) ctitles("","Proposed Equal Division") replace

regress PG_proposal T_DGGot0 T_DGGot10 T_PGNet10 T_PGNet20 T_SamePerson TX_Got0xSame TX_Got10xSame if DG_Own_Proposal==40, robust
lincom T_DGGot0+TX_Got0xSame
outreg using AppendixTableA3.rtf, se squarebrack bdec(2) starlevels(10 5 1) nolegend starloc(1) varlabels sigsymbols(* ** ***) ctitles("","Proposed 40/0 Division") merge replace

* Figure 2
set scheme plotplain
graph bar (mean) PG_proposal, over(T_DG_Partner_Given, label(angle(forty_five) labsize(small))) over(T_policynetpayoff) bar(1, fcolor(gs13) lcolor(black)) blabel(bar, position(outside) format(%9.2f)) yscale(range(0 1.05)) ytitle("Proportion Voting For Policy Proposal") xsize(8.5) ysize(11) by(T_partnertype, cols(1) note("Horizontal Axis is Division Game Outcome (Top) and Policy Game Net Policy Payoff (Bottom)", size(vsmall)))  name(figure2,replace) 
graph export Figure2.pdf, replace
graph export Figure2.png, replace

log close
